home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 691 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with stringcopy
  5. Date: 8 Jan 1996 16:24:37 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Message-ID: <4crgg5$d71@news.iag.net>
  8. References: <4clguu$9fs@eagle.novo.dk> <820933963snz@genesis.demon.co.uk> <4cq9dr$if9@ns.RezoNet.NET>
  9. NNTP-Posting-Host: pm3-orl29.iag.net
  10. X-Newsreader: WinVN 0.99.7
  11.  
  12. In article <4cq9dr$if9@ns.RezoNet.NET>, ray@ultimate-tech.com says...
  13. >
  14. >In referenced article, Lawrence Kirby says...
  15. >>Morten Brun writes:
  16. >>
  17. >>>How do i do a partial stringcopy i.e. copy from a specific position 
  18. >>>in a string and a certain numbers of bytes. I am looking for a 
  19. >>>function like target = Stringcopy(source, startpos, length)
  20. >>
  21. >>target[0] = '\0';
  22. >>strncat(target, source+startpos, length);
  23. >
  24. >...but use strncpy if you are overwriting some existing characters in 
  25. >target and don't want the target string to terminate after the copied 
  26. >characters.
  27.  
  28. strncpy will append a '\0' to target, when strlen(source+startpos) < length.
  29. The only way to guarantee that the target won't be terminated by strncpy
  30. would be some like:
  31.  
  32.   strncat(target, source+startpos, strlen(source+startpos));
  33.  
  34. or just use memcpy instead.  It would probably be faster, since it doesn't
  35. check for a '\0' in the source.
  36.  
  37. -- 
  38. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  39. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  40.  
  41.